﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using BryhtCommon;
using BryhtControls;

namespace MyRun.Views
{
    public partial class Setting : PhoneApplicationPage
    {
        public Setting()
        {
            InitializeComponent();
        }

        private void btnMapHistory_Click(object sender, RoutedEventArgs e)
        {
            var messageResult = MessageBox.Show("确定删除所有地图缓存吗？", "删除", MessageBoxButton.OKCancel);
            if (messageResult == MessageBoxResult.OK)
            {
                if (Isolated.RemoveFolder("MapTiles"))
                {
                    Isolated.CreateFolder("MapTiles");
                    MessageBox.Show("删除成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void btnChangeSian_Click(object sender, RoutedEventArgs e)
        {
            var messageResult = MessageBox.Show("确定删除新浪账号信息吗？", "删除", MessageBoxButton.OKCancel);
            if (messageResult == MessageBoxResult.OK)
            {
                if (Isolated.Setting.Contains("weiboToken"))
                {
                    Isolated.Setting.Remove("weiboToken");
                    Isolated.Setting.Remove("weiboExpires");
                    Isolated.Setting.Save();

                }
                else
                {
                    MessageBox.Show("账号为空~~~");
                }
            }
        }

        private void btnChangeRenren_Click(object sender, RoutedEventArgs e)
        {
            var messageResult = MessageBox.Show("确定删除人人账号信息吗？", "删除", MessageBoxButton.OKCancel);
            if (messageResult == MessageBoxResult.OK)
            {
                if (Isolated.Setting.Contains("renrenToken"))
                {
                    Isolated.Setting.Remove("renrenToken");
                    Isolated.Setting.Remove("renrenExpires");
                    Isolated.Setting.Save();

                }
                else
                {
                    MessageBox.Show("账号为空~~~");
                }
            }
        }

        private void btnChangeQzone_Click(object sender, RoutedEventArgs e)
        {
            var messageResult = MessageBox.Show("确定删除腾讯账号信息吗？", "删除", MessageBoxButton.OKCancel);
            if (messageResult == MessageBoxResult.OK)
            {
                if (Isolated.Setting.Contains("qqzoneToken"))
                {
                    Isolated.Setting.Remove("qqzoneToken");
                    Isolated.Setting.Remove("qqzoneExpires");
                    Isolated.Setting.Save();

                }
                else
                {
                    MessageBox.Show("账号为空~~~");
                }
            }
        }

        private void txtWeight_TextChanged(object sender, TextChangedEventArgs e)
        {
            Isolated.Set("Weight", txtWeight.Text);
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            txtWeight.Text = (Isolated.Get("Weight") ?? 70).ToString();
        }


        private void btnDeleteUserID_Click(object sender, RoutedEventArgs e)
        {
            if (Isolated.Remove("LiveUserId") && Isolated.Remove("LiveUserName"))
            {
                ThrowMessage.Show(MessageType.Prompt, "User信息已成功删除！");
            }
            
        }
    }
}